package leetcode.code120.Triangle;

import java.util.List;

public class Solution12003 extends Triangle {

	@Override
	public int minimumTotal(List<List<Integer>> triangle) {
		int len = triangle.size();
		int[][] arr = new int[len][len];
		int x = 0;
		int y = 0;
		for (List<Integer> l : triangle) {
			for (Integer num : l) {
				arr[x][y] = num;
				y++;
			}
			x++;
			y = 0;
		}
		for (int i = x - 2; i >= 0; i--) {
			for (int j = 0; j < i + 1; j++) {
				arr[i][j] = Math.min(arr[i][j] + arr[i + 1][j], arr[i][j] + arr[i + 1][j + 1]);
			}
		}
		return arr[0][0];
	}

	public static void main(String[] args) {
		Solution12003 so = new Solution12003();
		so.debug1();
		so.debug2();
		so.debug3();
		so.debug4();
	}

}
